package presenters;

import model.IPresenter;
import model.Model;
import views.PaymentInfoPanel;
import views.PersonInfoPanel;
import views.PersonalInfoPanel;
import views.PlanChoosePanel;

public class PersonInfoPresenter extends IPresenter {
	private PersonInfoPanel myPanel;
	private PaymentInfoPanel payPanel;
	private PaymentInfoPresenter payPresenter;
	private PersonalInfoPanel personPanel;
	private PersonalInfoPresenter personPresenter;
	private PlanChoosePanel planPanel;
	private PlanChoosePresenter planPresenter;

	public PersonInfoPresenter(PersonInfoPanel personInfoPanel,
			PaymentInfoPanel pay, PersonalInfoPanel panel_1,
			PlanChoosePanel panel_2) {
		// TODO Auto-generated constructor stub
		myPanel = personInfoPanel;
		payPanel = pay;
		payPresenter = payPanel.getMyPresenter();
		personPanel = panel_1;
		personPresenter = personPanel.getMyPresenter();
		planPanel = panel_2;
		planPresenter = planPanel.getMyPresenter();
	}

	public void populate() {
		if (Model.currentUserType == null) {
			return;
		}
		if (Model.currentUserType.equals("MEMBER")) {
			personPresenter.updateFields();
		
		String[] out = personPresenter.updateFields();
		payPresenter.populateFields(out[1]);
		int choice = 0;
		if ("Daily".equals(out[0])) {
			choice = 1;
		} else if ("Frequent".equals(out[0])) {
			choice = 2;
		} else if ("Occassional".equals(out[0])) {
			choice = 3;
		}
		planPresenter.choosePlan(choice);
		}
	}

	public void process() {
		// TODO Auto-generated method stub
		if (Model.getCurrentUserType().equals("MEMBER")) {
			String planChoice = planPanel.getPlanChoice();
			String cardNo = payPanel.process();
			personPanel.process(planChoice, cardNo);
		}
	}
}
